package server

import (
	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/transport/grpc"
	"github.com/go-kratos/kratos/v2/transport/http"
	"github.com/google/wire"
	tracesdk "go.opentelemetry.io/otel/sdk/trace"
	v1 "stwin.net/api/st-demo/demoV1"
	"stwin.net/demo/internal/service"
	"stwin.net/zoro/zconfig"
	"stwin.net/zoro/zoro"
	"stwin.net/zoro/ztracer"
)

var ProviderSet = wire.NewSet(ztracer.NewTracerProvider, NewGRPCServer, NewHttpServer)

func NewHttpServer(logger log.Logger, tp *tracesdk.TracerProvider, service *service.DemoService, bs zconfig.IZoroConfig) *http.Server {
	httpServer := zoro.NewHttpServer(bs, logger, tp)
	v1.RegisterDemoHTTPServer(httpServer, service) // TODO：注册 http

	// 额外增加一些 文件操作接口
	upload := httpServer.Route("/file")
	upload.POST("/upload", service.UploadFile)
	upload.GET("/download", service.Download)
	return httpServer
}

func NewGRPCServer(logger log.Logger, tp *tracesdk.TracerProvider, service *service.DemoService, bs zconfig.IZoroConfig) *grpc.Server {
	grpcServer := zoro.NewGrpcServer(bs, logger, tp)
	v1.RegisterDemoServer(grpcServer, service) // TODO：注册 rpc
	return grpcServer
}
